import Vue from 'vue';
import App from './app';
import { header,footer } from './components';
import { router } from './router'
import { store } from './store'
import vpUI from './plugins';
import ElementUI from 'element-ui'
import 'reset.css';
import 'animate.css';
import 'style-loader!./assets/css/vp.less';
import './assets/font_mq0pol3qs50icnmi/iconfont.css';
import 'element-ui/lib/theme-default/index.css'

import axios from 'axios';
import qs from 'qs';
import VueAxios from 'vue-axios'
Vue.use(ElementUI);

axios.defaults.baseURL = 'http://www.guoxuedasai.com/public/api';

//POST传参序列化
axios.interceptors.request.use((config) => {
    if(config.method  === 'post'){
        config.data = qs.stringify(config.data);
    }
    return config;
},(error) =>{
    alert("错误的传参");
    return Promise.reject(error);
});

axios.interceptors.response.use((res) =>{
    if(res.status != '200'){
        return Promise.reject(res);
    }
    return res.data;
}, (error) => {
    console.log("网络异常");
    return Promise.reject(error);
});

// 防止用户退出
window.onbeforeunload = onbeforeunload_handler;
window.onunload = onunload_handler;
function onbeforeunload_handler(){
    let warning = "确认退出?";
    return warning;
}

function onunload_handler(){
    let warning="重新打开页面导致了一些错误";
    alert(warning);
}

//低版本浏览器检测
let AgetBoo = false;

if ( /MSIE 6.0/ig.test(navigator.appVersion) ) {
    AgetBoo = true;
} else if ( /MSIE 7.0/ig.test(navigator.appVersion) ) {
    AgetBoo = true;
} else if ( /MSIE 8.0/ig.test(navigator.appVersion)) {
    AgetBoo = true;
}


if (AgetBoo) {
    alert('您的浏览器版本过低，点击升级浏览器');
    location.href = 'http://rj.baidu.com/soft/detail/14744.html?ald';
}

Vue.use(VueAxios, axios);
Vue.use(vpUI);

Vue.component('v-header', header);
Vue.component('v-footer', footer);

new Vue({
    el: '#app',
    router,
    store,
    render: h => h(App)
}).$mount('#main');
